package com.iam.api.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.iam.core.base.BaseCommonController;
import com.iam.core.entities.IParams;
import com.iam.core.entities.Result;
import com.iam.core.utils.ResultUtil;
import com.iam.core.model.SysArgs;
import com.iam.core.service.ArgsService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;


@RestController
@RequestMapping("/api/sysArgs")
public class SysArgsController extends BaseCommonController<SysArgs> {


    @Autowired
    private ArgsService service;

    @Override
    public Result index(@RequestBody IParams params) {
        return ResultUtil.success(service.selectPage(params));
    }

    /**
     * 分页查询
     * @param entity
     * @return
     */


    @GetMapping("/logo")
    public Result logo(SysArgs entity, HttpServletRequest request) {
        QueryWrapper wrapper = new QueryWrapper<SysArgs>();
        wrapper.eq("code", entity.getCode());
        SysArgs args = service.getOne(wrapper);
        return ResultUtil.success(args);
    }

    /**
     * 获取详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result details(@PathVariable Integer id) {
        return super.details(id);
    }

    /**
     * 编辑 更新
     * @param entity
     */
    @PutMapping
    public Result update(@RequestBody SysArgs entity) {
        entity.setUpdateAt(new Date());
        return super.update(entity);
    }

    /**
     * 获取service
     */
    @Override
    public ArgsService getiService() {
        return service;
    }

    /**
     * 获取模块名称
     */
    @Override
    public String getMouduleName() {
        return "系统参数";
    }

}